/**
 * svcpkg contrller
 * add by tangjiannan
 */
package com.crm.business.web.svcpkg.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.crm.business.web.svcpkg.service.SvcPkgService;
import com.crm.common.web.controller.WebCommonController;

/**
 * 套餐管理操作类
 * 
 * @author tangjiannan
 * 
 */
@Controller("svcpkg_svcpkgController")
public class SvcPkgController extends WebCommonController {
    /** Logger */
    private static final Logger LOG = Logger
            .getLogger(SvcPkgController.class);
    /** Main Service */
    @Resource(name = "svcpkg_svcPkgService")
    private SvcPkgService service = null;

    /**
     * Show svcPkg main Page
     * 
     * @return main page
     */
    @RequestMapping("show_svcpkg.shtm")
    public ModelAndView add(HttpServletRequest req) {
        ModelAndView mv = createOpenPageMV(req);
        String module = req.getParameter("module");
        if ("add".equals(module)) {
            mv.setViewName("svcpkg/p00_svcpkg_add.jsp");
        } else {
            mv.setViewName("svcpkg/p01_svcpkg_main.jsp");
        }
        return mv;
    }

    /**
     * query svcitems
     * 
     * @param req HttpServletRequest
     * @param resp HttpServletResponse
     */
    @RequestMapping("svcpkg/query.shtm")
    public void query(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("query svcpkgs info beging...");

        // request parameters
        Map<String, Object> params = getReqParams(req);

        // query
        this.service.doQuery(params);

        Map<String, Object> output = getDefaultResult();
        output.put("svcitems", params.get("svcitems"));
        outputJSON(resp, output);

        LOG.info("query svcpkgs info finshed.");
    }

    /**
     * add_svcpkg
     * 
     * @param req HttpServletRequest
     * @param resp HttpServletResponse
     */
    @RequestMapping("svcpkg/add_svcpkg.shtm")
    public void insert(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("add svcpkg info  beging...");
        // request parameters
        Map<String, Object> params = getReqParams(req);

        service.addPkgAndRelation(params);

        LOG.info("add svcpkg info end...");
        Map<String, Object> output = getDefaultResult();
        outputJSON(resp, output);
    }

    @RequestMapping("svcpkg/delpkg.shtm")
    public void del(HttpServletRequest req, HttpServletResponse resp) {
        LOG.info("delete svcpkg info beging...");
        // request parameters
        Map<String, Object> params = getReqParams(req);

        // query
        boolean result = this.service.delpkgAndRel(params);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("success", result);
        outputJSON(resp, map);
        LOG.info("delete svcpkg info finshed.");
    }
}
